package com.yueqian.Dao;

import com.yueqian.Utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;

public class UpdateEmployeeDao {
    //根据修改用户名
    public  Boolean updateUsername(String number,String username){
        Connection connection = JDBCUtils.Connection();
        String sql = "update employee set username = ? where number = ?";
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, number);
            int i1 = preparedStatement.executeUpdate();
            if(i1 > 0)
            {       System.out.println("修改成功");
            return true;}
             else
                  {
                      System.out.println("修改失败");
                      return false;
                  }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
    //修改密码
    public  Boolean updatePassword(String number,String password){
        Connection connection = JDBCUtils.Connection();
        String sql = "update employee set password = ? where number = ?";
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, password);
            preparedStatement.setString(2, number);
            int i1 = preparedStatement.executeUpdate();
            if(i1 > 0)
            {       System.out.println("修改成功");
                return true;}
            else
            {
                System.out.println("修改失败");
                return false;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    //用户名和密码修改
    public Boolean updateUser(String number,String username, String password){
        Connection connection = JDBCUtils.Connection();
        String sql = "update employee set username=? , password = ?  where number = ?";
        try {
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, username);
            preparedStatement.setString(2, password);
            preparedStatement.setString(3, number);
            int i1 = preparedStatement.executeUpdate();
            if(i1 > 0)
            {       System.out.println("修改成功");
                return true;}
            else
            {
                System.out.println("修改失败");
                return false;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


    }
}
